﻿#pragma once
#include <tuple>
#include "Parameter.h"
#include "AstType.h"
#include "AstFunction.h"

class AstDef;
class AstGetClass;
class ClassInstanceType;

/**
*	原始类区块
*/
class AstClass : public AstNode {
public:
	virtual CodeGen* makeGen(SiContext* parent);
	CodeGen* makeNew(std::vector<std::pair<std::string, CodeGen*> >& args );
	ClassInstanceType* getInstance(std::vector<std::pair<std::string, CodeGen*> >& args);
public:
	bool singleton = false;

	AstGetClass* inherit;	// 继承
	std::vector<AstNode*> block;

	std::map<std::string, AstType* > memberTypes;


private:
	std::vector<AstFunction*> _construstors;	// 构造函数
	// 类的上下文，为类定义时的上下文
	SiContext* _parent;
	bool _templated = false;

	typedef std::pair<AstFunction*, AstFunction::OrderedParameters *> CreaterOrdered;
	CreaterOrdered getCreaterOrderd(std::vector<std::pair<std::string, CodeGen*> >& args);

	typedef std::pair<ClassInstanceType*, FunctionInstance*> InstancePair;
	std::map<intptr_t, InstancePair> _cached;
	InstancePair _generated;
private:
	InstancePair generateClass(
		AstFunction* creater,
		AstFunction::OrderedParameters *ordered
	);
};
